<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>中联众鑫建筑机械</title>
<link rel="stylesheet" media="all" type="text/css" href="admin.css" />
<script type="text/javascript" charset="utf-8" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="../ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
	function addProduct() {
		if (!validate()) {
			return false;
		}
		
		var content = UE.getEditor('editor').getContent();
		var contentInput = document.getElementById("content");
		contentInput.value = content;
		return true;
	}

	function validate() {
		if (!addNewForm.name.value) {
			alert("请输入标题!");
			return false;
		}

		if (!addNewForm.catalog.value) {
			alert("请输入作者!");
			return false;
		}
		
		return true;
	}

	function selectThumbnail(element) {
		var name = element.name;
		var isThumbnail0 = document.all.isThumbnail0;
		var isThumbnail1 = document.all.isThumbnail1;
		var isThumbnail2 = document.all.isThumbnail2;
		if (element.checked) {
			switch (name) {
				case "isThumbnail0":
					isThumbnail1.checked = false;
					isThumbnail2.checked = false;
					break;
				case "isThumbnail1":
					isThumbnail0.checked = false;
					isThumbnail2.checked = false;
					break;
				case "isThumbnail2":
					isThumbnail1.checked = false;
					isThumbnail0.checked = false;
					break;
			}
		}	
	}
</script>
</head>
<body>
<div class="center">
	<?php include 'top.php';?>
	<div class="box centent">
		<div class="right">
			<div class="title">添加产品</div>
			<div>
				<form class="autoform" name="addProductForm" method="post" action="add_product_action.php" enctype="multipart/form-data">
					<input name="images" type="hidden" />
					<table border="0" cellpadding="5" cellSpacing="5">
						<tr>
							<td width="80" class="label">产品名称:</td>
							<td colspan=2 class="field"><input name="name" type="text" style="width:500px;" /></td>
						</tr>
						<tr>
							<td class="label">产品分类:</td>
							<td colspan=2 class="field"><select name="catalog">
									<option value="elevator">电梯零配件</option>
									<option value="towerfoot">塔基配件</option>
								</select></td>
						</tr>
						<tr>
							<td class="label">上传文件:</td>
							<td class="field">
								<input name="isThumbnail0" type="checkbox" alt="选择索引图片" onclick="selectThumbnail(this);"/>
								<input id="addImage0" name="addImage0" type="file" value="添加图片"/>
							</td>
						</tr>
						<tr>
							<td></td>
							<td class="field" style="vertical-align:middle;">
								<input name="isThumbnail1" type="checkbox" alt="选择索引图片" onclick="selectThumbnail(this);" />
								<input id="addImage1" name="addImage1" type="file" value="添加图片"/>
							</td>
						</tr>
						<tr>
							<td></td>
							<td class="field" style="vertical-align:middle;">
								<input name="isThumbnail2" type="checkbox" alt="选择索引图片" onclick="selectThumbnail(this);" />
								<input id="addImage2" name="addImage2" type="file" value="添加图片"/>
							</td>
						</tr>
						<tr>
							<td colspan="3">
								<script id="editor" type="text/plain" style="height:500px;"></script>
								<input id="content" name="content" type="hidden" />
							</td>
						</tr>
						<tr>
							<td colspan="3" align="center"><input type="submit" value="提 交" onclick="return addProduct();"><input type="reset" value="重 置"></td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
	<?php include 'bottom.php';?>
</div>
</body>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('editor');
    
    var addImage = document.getElementById("addImage");
    addImage.addEventListener("change", function(event) {
        /*var files = addImage.files;
        var len = files.length;
	    for (var i = 0; i < len; i++) {
	    	uploadImage(files[i].name, files[i]);
	    }*/
    });
</script>
</html>